

let request = require('request');


let counter = 0;
let total = 1000;
let completed = 0;
let canExit = false;
function req() {
    counter++;
    request('http://localhost:3000',(err,response,body)=>{
        if(!err){
            console.log('body:',body);
        }else{
            console.log('err:',err);
        }

        completed++;
        if(completed >= total){
            console.log('全部处理完毕!');
            canExit = true;
        }
    });
}


for(let i = 0; i < total; ++i){
    req();
}

let invId = setInterval(()=>{
    if(canExit){
        clearInterval(invId);
        console.log('退出......');
        process.exit(0);
    }
},1000);
